<template>
	<view class="ys">
		<view class="form">
			<uni-section title="商品单号" type="line">
				<view class="inputbox">
					<uni-easyinput v-model="order_id" disabled=""></uni-easyinput>
				</view>
			</uni-section>
			<uni-section title="物流公司" type="line">
				<view class="inputbox">
					<uni-data-select v-model="express_company" :localdata="list"></uni-data-select>
				</view>
			</uni-section>

			<uni-section title="物流单号" type="line">
				<view class="inputbox">
					<uni-easyinput v-model="express_no" trim placeholder="请输入物流单号" clearSize="20"></uni-easyinput>
				</view>
			</uni-section>
		</view>
		<button class="btn" @click="delivery" :loading="loading" :disabled="loading">提交</button>
	</view>
</template>

<script>
	import {
		getExpress,
		delivery
	} from "@/api/user.js"
	export default {
		data() {
			return {
				order_id: '',
				list: [],
				express_company: '',
				express_no: '',
				loading: false
			}
		},
		onLoad(e) {
			if (e.id) {
				this.order_id = e.id
				this.getExpress()
			}
		},
		methods: {
			delivery() {
				this.loading = true
				delivery({
					id: this.order_id,
					express_company: this.express_company,
					express_no: this.express_no,
				}).then(res => {
					this.loading = false
					if (res.code == 0) {
						uni.$showMsg(res.msg, function() {
							uni.navigateBack()
						})
					} else {
						uni.$showMsg(res.msg)
					}
				})
			},
			getExpress() {
				getExpress().then(res => {
					if (res.code == 0) {
						var list = res.data
						list.forEach(item => {
							this.list.push({
								text: item.name,
								value: item.name
							})
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		.inputbox {
			width: 96%;
			margin: 0px auto;
		}

		.form {
			padding-bottom: 15px;
			background: #fff;
		}

		.btn {
			button {
				color: #fff;
				font-size: 16px;
				letter-spacing: 1px;
				margin: 30px auto;
				width: 96%;
			}
		}
	}
</style>